package com.oocl.webmvc_2.controller;

import java.util.List;
import java.util.UUID;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oocl.webmvc_2.pojo.Customer;
import com.oocl.webmvc_2.service.CustomerService;
import com.oocl.webmvc_2.service.impl.CustomerServiseFactory;
@Controller
public class CustomerController {
	private CustomerService customerService;
	
	public CustomerController() {
		customerService = CustomerServiseFactory.getInstance();
	}

	@ResponseBody
	@RequestMapping(value="/addCustomer",method=RequestMethod.POST,consumes="application/json")
	public Customer addCustomer(@RequestBody Customer c){
		c.setId(UUID.randomUUID().toString());
		Customer customer = customerService.addCustomer(c);
		return customer;
	}
	
	@ResponseBody
	@RequestMapping(value="/deleteCustomer",method=RequestMethod.POST)
	public Customer deleteCustomer(String id){
		Customer delCustomer = customerService.deleteCustomer(id);
		return delCustomer;
	}
}
